
ClassFactory.defineClass("myPickListForSingle", TextItem);

myPickListForSingle.addProperties({

	icons:[{src: "selectPicker.gif", height: 22}], // could specify a different image here

	iconClick : function (form, item, icon) {
		
		var iconRect = this.getIconPageRect(icon);
		
		var that = this;		
		var ds = item.optionDataSource;

		var fields = isc.clone(item.pickListFields);

		var dialogTitle = null != item.dialogTitle ? item.dialogTitle : "";
		
		var dialogShowHeader = null != item.dialogTitle ? true : false;
		
		var listShowFilterEditor = null != item.showFilterEditor ? item.showFilterEditor : false;
		
		var list = isc.M3ListGrid.create({
			dataSource:ds, 
			autoDraw:false, 
			showFilterEditor: listShowFilterEditor,
			filterOnKeypress: true,
			// selectionAppearance:"checkbox",
			showSelectedStyle:false,
			recordDoubleClick :function(){
				var df = item.valueField != null ? item.valueField : item.displayField;
				var selection = this.getSelection();

				var str = selection[0][df];

				that.setValue(str);
				try{
					item.getPickListCloseEvent(selection[0],str);
				}catch(e){}
				dialog.hide();
			}
		});			
		
		list.defaultFields = fields;
		list.setFields(fields);
		
		
		var listCriteria = null != item.getPickListFilterCriteria() ? item.getPickListFilterCriteria():null;
		
		var _width= this.pickListWidth ? this.pickListWidth : 300;
		
		var dialog = Dialog.create({
			title: dialogTitle,
			autoDraw: false,
			autoCenter: true,
			isModal: true,
			showModalMask: true,
			showHeader: dialogShowHeader,
            showToolbar: false,
			width: _width,
			height: 310,
			bodyDefaults: {layoutMargin:1, membersMargin:1}
		});

		dialog.addItem(list);

		dialog.show();
		
		var operation = "fetch";
		
		if(item.operationId != null) {
			operation = item.operationId;
		}
		
		isc.DataSource.get(ds).fetchData(listCriteria, function(dsResponse, data){
			// alert(isc.echoAll(data));
			list.setData(data)
		}, {operationId:operation});	
		
	},change:function(form, item, value, oldValue){
		
	}
	
	
});

